package models

import (
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego"
)

type SystemUser struct {
	Id int
	Username string
	Password string
	RoleId   int
}

type SystemRole struct {
	Id int
	Rolename string
}



/**
根据用户名密码获取用户
 */
func GetUserByUsername(username string,password string) (ok bool,msg string,user SystemUser){

	o := orm.NewOrm()
	err := o.QueryTable("system_user").Filter("username", username).Filter("password",password).One(&user)

	ok = true
	if err == orm.ErrMultiRows {
		ok = false
		msg = "在数据库内找到了多个用户："+ username + ",请联系管理员!"
	}
	if err == orm.ErrNoRows {
		ok = false
		msg = "您的用户名和密码不匹配，请检查后重新输入!"
	}

	beego.Info(msg)
	beego.Info(user)

	return ok,msg,user
}